package lk.mrt.cse.wihidum.listener.storage;

import org.apache.log4j.*;
import org.hibernate.*;
import org.hibernate.criterion.*;
/**
 * Created by IntelliJ IDEA.
 * User: Will
 * Date: Feb 26, 2010
 * Time: 10:52:23 AM
 * To change this template use File | Settings | File Templates.
 */
public class SubscriptionDAO
{
      Session session = null;
      private static final Logger logger = Logger.getLogger (SubscriptionDAO.class);

    /**
     * Default constructor
     */
    public SubscriptionDAO ()
    {
        this.session = DataBaseManager.getSessionFactory ().getCurrentSession ();
    }


    public boolean saveSubscriber (Subscription subscription)
    {
        try
        {
            Transaction tx = session.beginTransaction ();
            session.save (subscription);
            tx.commit ();
            logger.info ("Subscription saved successfully");
            return true;
        }
        catch (HibernateException ex)
        {
            logger.error ("Error in saving subscriber", ex);
            return false;
        }
    }

}
